{% extends 'base.html' %}
{% load i18n %}

{% block title %}{{ page_title }} - {{ block.super }}{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-3 flex-wrap">
    <h1 class="h2 text-success mb-0"><i class="bi bi-map-fill me-2"></i> {{ field.name }}</h1>
    <div class="btn-group mt-2 mt-md-0" role="group" aria-label="Field Actions">
        <a href="{% url 'field_management:field_edit' field.pk %}" class="btn btn-sm btn-outline-primary"><i class="bi bi-pencil-square"></i> {% trans "编辑" %}</a>
        <a href="{% url 'field_management:field_delete' field.pk %}" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i> {% trans "删除" %}</a>
    </div>
</div>

<div class="card mb-4 shadow-sm">
    <div class="card-header">{% trans "基本信息" %}</div>
    <div class="card-body">
        <dl class="row">
            <dt class="col-sm-3">{% trans "名称/编号" %}</dt><dd class="col-sm-9">{{ field.name }}</dd>
            <dt class="col-sm-3">{% trans "负责人" %}</dt><dd class="col-sm-9">{{ field.owner.username }}</dd>
            <dt class="col-sm-3">{% trans "面积" %}</dt><dd class="col-sm-9">{{ field.area }} {% trans "亩" %}</dd>
            <dt class="col-sm-3">{% trans "位置" %}</dt><dd class="col-sm-9">{{ field.location|default:_("N/A") }}</dd>
            <dt class="col-sm-3">{% trans "坐标" %}</dt>
            <dd class="col-sm-9">
                 {% if field.latitude and field.longitude %}
                    <i class="bi bi-pin-map-fill text-muted"></i> {{ field.latitude }}, {{ field.longitude }}
                     {# Add link to map if desired: #}
                     {# <a href="https://www.google.com/maps?q={{ field.latitude }},{{ field.longitude }}" target="_blank" class="ms-2"><i class="bi bi-geo-alt"></i> 在地图上查看</a> #}
                {% else %}
                    {% trans "N/A" %}
                {% endif %}
            </dd>
            <dt class="col-sm-3">{% trans "土壤类型" %}</dt><dd class="col-sm-9">{{ field.soil_type|default:_("N/A") }}</dd>
            <dt class="col-sm-3">{% trans "灌溉来源" %}</dt><dd class="col-sm-9">{{ field.irrigation_source|default:_("N/A") }}</dd>
            <dt class="col-sm-3">{% trans "备注" %}</dt><dd class="col-sm-9">{{ field.notes|linebreaksbr|default:_("无") }}</dd>
        </dl>
         <small class="text-muted d-block text-end">
             {% trans "创建时间" %}: {{ field.created_at|date:"Y-m-d H:i" }} | {% trans "最后更新" %}: {{ field.updated_at|date:"Y-m-d H:i" }}
         </small>
    </div>
</div>

<div class="card shadow-sm">
    <div class="card-header d-flex justify-content-between align-items-center">
        <span><i class="bi bi-calendar-check me-2"></i> {% trans "最近种植记录" %}</span>
        <a href="{% url 'planting_records:record_add_for_field' field.pk %}" class="btn btn-success btn-sm"><i class="bi bi-plus-lg"></i> {% trans "添加新记录" %}</a>
    </div>
    <div class="card-body">
        {% if planting_records %}
        <ul class="list-group list-group-flush">
            {% for record in planting_records %}
            <li class="list-group-item d-flex justify-content-between align-items-center">
                <a href="{{ record.get_absolute_url }}" class="text-decoration-none">
                    <strong class="text-primary">{{ record.rice_variety }}</strong> - {{ record.planting_date|date:"Y-m-d" }} ({{ record.get_planting_method_display }})
                </a>
                <span class="badge bg-light text-dark rounded-pill">{{ record.created_at|timesince }} {% trans "前" %}</span>
            </li>
            {% endfor %}
        </ul>
         {% if field.planting_records.count > 10 %} {# Assuming we limited display to 10 in view #}
             <div class="text-center mt-3">
                <a href="{% url 'planting_records:record_list_by_field' field.pk %}" class="btn btn-outline-secondary btn-sm">{% trans "查看此田块所有种植记录" %}</a>
             </div>
         {% endif %}
        {% else %}
        <p class="text-muted text-center">{% trans "此田块暂无种植记录。" %}</p>
        {% endif %}
    </div>
</div>

<div class="mt-4">
    <a href="{% url 'field_management:field_list' %}" class="btn btn-secondary"><i class="bi bi-arrow-left-circle"></i> {% trans "返回田块列表" %}</a>
</div>
{% endblock %}